#include "font.h"

namespace TGO
{
	Font& UIFont() 
	{
		static Font uiFont;
		return uiFont;
	}

	Font& DialogFont()
	{
		static Font dialogFont;
		return dialogFont;
	}
}

Font::Font()
{
	mFont = NULL;
	mBias = 1;
}

Font::~Font()
{
	OnRelease();
}

void Font::OnRelease()
{
	SAFE_RELEASE( mFont );
}

void Font::OnInit( String fontType, UINT width, UINT height, UINT weight, bool italic )
{
	mBias = width / bias_factor;
	HR( D3DXCreateFont( RenderFrame::GetD3DDevice(),
						height,
						width,
						weight,
						0,
						italic,
						DEFAULT_CHARSET,
						OUT_DEFAULT_PRECIS,
						DEFAULT_QUALITY,
						DEFAULT_PITCH | FF_DONTCARE,
						fontType,
						&mFont ) );
}

void Font::DrawText( String text, RECT area, D3DCOLOR color, ID3DXSprite* sprite )
{
	mFont->DrawTextW( sprite, text, -1, &area, DT_VCENTER | DT_CENTER, color );
}

void Font::DrawTextShadowed( String text, RECT area, D3DCOLOR color, ID3DXSprite* sprite )
{
	RECT biasArea = area;
	biasArea.right += mBias;
	biasArea.left += mBias;
	biasArea.top += mBias;
	biasArea.bottom += mBias;

	DrawText( text, biasArea, 0xFF000000, sprite );
	DrawText( text, area, color, sprite );
}